﻿package 
{
	import chamans.away.chaise;
	import chamans.away.sol;
	import chamans.engine.Away4;
	import chamans.engine.Jiglib;
	import chamans.life.PoissonDisk;
	import flash.display.BitmapData;
	import flash.geom.Vector3D;
	
	[SWF(backgroundColor="#000000", frameRate="120", width="960", height="540")]
	
	public class baseJiglib extends Away4
	{
		public function baseJiglib()
		{
			var DEF:Object={  
				phy:true, fog:true, reflect:true, sky:true,
				titre:"BASE",  	message:"Welcome, press space to generate chair",
				// [ground, sky, building, fog, fogDistance, quality:0/1/2, hazeAlpha, construct , building or not]
				color:[0x8E806F, 0x195BB2, 0x6491CC, 0x8E806F, 600, 0, 1, false, true],
				// camera set
				fov:50, far:5000, near:1, type:"fps", H:90, V:-90, 
				position : new Vector3D(0, 100, -200), targetDistance :1000
			}
			//  ( final function, loop function, definition object ) 
			super(INIT3D, GETKEYS, DEF);
		}
		private function INIT3D():void
		{
			// light set
			Lights.add("point", 0xeeEFff, -405, 330, -405, .8, 1, false , null, true ,300, 3000);
			Lights.add("point", 0xFFEFee, 405, 330, -405, .8, 1, false , null, true ,300, 3000);
			//	physics set
			if(phyOn){ physics=new Jiglib(this, 6, 0.16); physics.add_Plan(.3, .8); }
			// load teste.swf : a flash movieclip with 4 clip see chamans/away/map.as
			Camera.plan( 'mapbase', .3,  new Vector3D(50,.5,2048), null, TMP);
		}	
		private function TMP():void
		{
			G = new sol( this, NEXT0);
			SYS.VISOR( true ); 
		}
		private function NEXT0():void 
		{ 
			C = new chaise( this, RESET );
			Shadows(1);
		}	
		public function RESET():void 
		{ 
			if(actif){C.Delete();actif=false;}
			var i:int;
			var W:int=2048;
			var MAXI:int=40;
			var sampler:PoissonDisk = new PoissonDisk({w:W, max:MAXI, fail:MAXI , Hmap:Camera.planTop.mapDistrib, Rmin:2, Rmax:10 });
			for each( var p:Vector3D in sampler.List)
			C.clone(new Vector3D(p.x-(W>>1), TOOL.Ran(1000, 200), p.y-(W>>1)), sampler.List[i].z );//43
			sampler.List=null;
			actif=true;
		}
		private function GETKEYS():void 
		{	
			if( KEY.isDown( 32 ) && Ppress){ RESET(); Ppress=false }// space
			if( KEY.isUp( 32 ) && actif)Ppress=true;
		}
		
		private var G:sol;
		private var C:chaise;
		private var Ppress:Boolean=true;
		private var actif:Boolean=false;
		private var HHmap:BitmapData;
		
	}}
